package com.lancoo.tyjx.multichatroom.activity;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

import com.lancoo.tyjx.multichatroom.constants.Constants;
import com.lancoo.tyjx.multichatroom.image.ImgConfig;
import com.lancoo.tyjx.multichatroom.utils.JsonUtil;

import java.util.HashMap;
import java.util.Timer;
import java.util.TimerTask;

public class MyApplication {
    private static final String TAG = "MyApplication";
    private static Application context;
    public static SharedPreferences sharedPreferences;
    public static HashMap<String, String> emotionMap;
    public static double lat = 23.117055306224895;
    public static double lon = 113.2759952545166;

    public static Application getInstance() {
        if (null == context) {
            Log.e(TAG, "未初始化");
        }
        return context;
    }

    // 初始化
    public static void init(Application application) {
        context = application;
        String emotionJson = JsonUtil.getEmotionJson("emotion_list.json", context);
        emotionMap = JsonUtil.parseEmotionJson(emotionJson);
        sharedPreferences = context.getSharedPreferences(Constants.SHARED_PREFERENCES, Context.MODE_PRIVATE);
        ImgConfig.initImageLoader();

        new Timer().schedule(new TimerTask() {  //1秒后开始，5分钟上传一次自己的位置
            @Override
            public void run() {
                if (MyApplication.sharedPreferences.getBoolean("isShare", true)) {

                }
            }
        }, 1000, Constants.UPDATE_TIME);
    }

    public static HashMap<String, String> getEmotionMap() {
        if (emotionMap == null || emotionMap.size() <= 0) {
            String emotionJson = JsonUtil.getEmotionJson("emotion_list.json", context);
            emotionMap = JsonUtil.parseEmotionJson(emotionJson);
        }
        return emotionMap;
    }
}
